﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESOL.Common.Entity;
using Suzsoft.Smart.Data;
using ESOL.Common;

namespace ESOL.Business
{
    public class SalesCommonFunctions
    {
        public static decimal GetDeliveryOrderTotalAmout(string deliveryId)
        {
            string sql = @"SELECT SUM(CONVERT(DECIMAL(18,2),DI.PRICE * DI.QTY)) AS TOTAL_AMOUNT
                            FROM SALES_DELIVERY_ITEM DI
                            INNER JOIN SALES_DELIVERY_ORDER DO ON DO.DELIVERY_ORDER_ID = DI.DELIVERY_ORDER_ID
                            WHERE DO.DELIVERY_ORDER_ID = '" + deliveryId + @"'
							GROUP BY DO.DELIVERY_ORDER_ID";
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string amount = ds.Tables[0].Rows[0]["TOTAL_AMOUNT"].ToString();
                if (CommonFunctions.IsDecimal(amount))
                {
                    return CommonFunctions.ToDecimal(amount);
                }
            }
            return 0;
        }
    }
}
